import os

def merge_sql_files(directory, output_file):
    # 创建或清空输出文件
    with open(output_file, 'w') as outfile:
        # 遍历目录中的所有文件
        for filename in os.listdir(directory):
            # 检查文件是否为SQL文件
            if filename.endswith('.sql'):
                filepath = os.path.join(directory, filename)
                # 打开并读取SQL文件内容
                with open(filepath, 'r') as infile:
                    # 将内容写入输出文件
                    outfile.write(infile.read())
                    # 可选：在每个文件间添加一个空行以区分不同脚本
                    outfile.write("\n\n")

# 指定目录和输出文件名
directory = 'D:/06git/01python/02vanna/02导入训练sql数据/smartlight/data'
output_file = 'D:/06git/01python/02vanna/02导入训练sql数据/smartlight/data/merged_sql.sql'

# 调用函数
merge_sql_files(directory, output_file)